package com.songlanyun.modules.withdraw.entity;

import cn.afterturn.easypoi.excel.annotation.Excel;
import cn.hutool.core.util.DesensitizedUtil;
import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.songlanyun.common.drive.RootEntity;
import com.songlanyun.common.enums.WithdrawConstant;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;

import java.math.BigDecimal;
import java.io.Serializable;
import java.util.Date;

/**
 * 提现列表
 *
 * @author Mark
 * @email sunlightcs@gmail.com
 * @date 2020-11-20 17:47:55
 */
@Data
@TableName("yxt_sale_withdraw")
public class Withdraw extends RootEntity<Long, Withdraw> implements Serializable {
    private static final long serialVersionUID = 1L;

    {
        money = BigDecimal.ZERO;
        commissionCost = BigDecimal.ZERO;
    }

    /**
     *
     */
    @TableId
    private Long id;
    /**
     * 提现类型
     * 0商家所得提现，
     * 1会员分佣金提现
     */
    private WithdrawConstant.WithdrawType withdrawType;

    /**
     * 业务单号(提现单号)
     */
    @Excel(name = "提现单号", orderNum = "1", width = 30)
    private String businessCode;

    /**
     * 提现金额
     */
    @Excel(name = "提现金额", orderNum = "2", width = 10)
    private BigDecimal money;

    /**
     * 提现手续费
     */
    @Excel(name = "提现手续费", orderNum = "3", width = 10)
    private BigDecimal commissionCost;


    /**
     * 流水号（第三方支付单号手填）
     */
    @Excel(name = "交易流水号", orderNum = "9", width = 40)
    private String thirdPayCode;
    /**
     * 提现方式：
     * 0微信，
     * 1支付宝，
     * 2银行卡
     * 3现金支付
     */
    @Excel(name = "提现方式", orderNum = "4", replace = {"微信_0", "支付宝_1", "银行卡_2", "现金支付_3"}, width = 10)
    private Integer paymentTerm;
    /**
     * 创建时间
     */
    @Excel(name = "申请时间", orderNum = "6", format = "yyyy-MM-dd HH:mm:ss", width = 20)
    @TableField(fill = FieldFill.INSERT)
    private Date createTime;
    /**
     * 提现人
     */
    @Excel(name = "提现人", orderNum = "5", width = 15)
    private String payee;
    /**
     * 提现账户
     */
//    @Excel(name = "提现账户",orderNum = "5",width = 20)
    private String withdrawAccount;

    /**
     * 提现手机
     */
    @Excel(name = "提现手机", orderNum = "5", width = 15)
    private String withdrawMobile;

    public String getWithdrawMobileDesensitized() {
        if (StringUtils.isNotEmpty(this.withdrawMobile) && this.withdrawMobile.length() >= 11) {
            return DesensitizedUtil.mobilePhone(this.withdrawMobile);
        }
        return this.withdrawMobile;
    }

    /**
     * 商家名称
     */
    private String shopName;
    /**
     * 银行名称
     */
    private String bankName;
    /**
     * 会员手机号
     */
    private String userMobile;
    /**
     * 审核状态
     * 0待审核
     * 1审核通过
     * 2审核不通过
     */
    @Excel(name = "审核状态", orderNum = "7", replace = {"待审核_0", "审核通过_1", "审核不通过_2"}, width = 10)
    private Integer verifyStatus;
    /**
     * 审核人
     */
    @Excel(name = "审核人", orderNum = "8", width = 15)
    private String verifyMan;
    /**
     * 审核时间
     */
    private Date verifyTime;
    /**
     * 审核意见
     */
    private String verifyOpinion;
    /**
     * 审核备注
     */
    private String verifyRemark;
    /**
     * 用户类型
     * 0：会员
     * 1：商家
     */
    private WithdrawConstant.UserType userType;
    /**
     * 身份id(会员：会员id，商家：商家id)
     */
    private Long identityId;
    /**
     * 打款状态
     * 0：未打款
     * 1：已打款
     */
    @Excel(name = "提现状态", orderNum = "11", replace = {"未打款_false", "已打款_true"}, width = 10)
    private Boolean remitStatus;
    /**
     * 打款人
     */
    private String remitMan;
    /**
     * 打款时间
     */
    @Excel(name = "打款时间", orderNum = "10", format = "yyyy-MM-dd HH:mm:ss", width = 20)
    private Date remitTime;

    @Override
    public Long getIdentity() {
        return id;
    }

    /**
     * 保存身份
     */
    public void saveUserType(WithdrawConstant.UserType userType, Long userId) {
        this.userType = userType;
        this.identityId = userId;
    }

}
